﻿package mlc.haxe.output;
import haxe.PosInfos;

/**
 * An output handler that can hold multiple output handlers inside. This class allows you to wire multiple output handlers to
 * one console.
 */
class CompositeOutputHandler implements ConsoleOutputHandler {
	private var outputHandlers:List<ConsoleOutputHandler>;
	/**
	 * Create a new composite output handler.
	 */
	public function new():Void {
		outputHandlers = new List<ConsoleOutputHandler>();
	}
	/**
	 * Adds an output handler to the internal list.
	 */
	public function addOutputHandler(value:ConsoleOutputHandler):Void {
		outputHandlers.add(value);
	}
	public function clearOutput():Void {
		for (outputHandler in outputHandlers) {
			outputHandler.clearOutput();
		}
	}
	/**
	 * Removes an output handler from the internal list. If the passed output handler is not in the internal list, calling this
	 * method does nothing.
	 */
	public function removeOutputHandler(value:ConsoleOutputHandler):Void {
		outputHandlers.remove(value);
	}
	#if debug
	private function toString():String {
		return "[ConsoleOutputHandler]";
	}
	#end
	public function writeAdvancedString(value:String, color:Int, breakline:Bool):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeAdvancedString(value, color, breakline);
		}
	}
	public function writeBool(value:Bool, positionInformation:PosInfos):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeBool(value, positionInformation);
		}
	}
	public function writeFloat(value:Float, positionInformation:PosInfos):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeFloat(value, positionInformation);
		}
	}
	public function writeInt(value:Int, positionInformation:PosInfos):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeInt(value, positionInformation);
		}
	}
	public function writeNull(positionInformation:PosInfos):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeNull(positionInformation);
		}
	}
	public function writeString(value:String, positionInformation:PosInfos):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeString(value, positionInformation);
		}
	}
	public function writeXml(value:Xml, positionInformation:PosInfos):Void {
		for (outputHandler in outputHandlers) {
			outputHandler.writeXml(value, positionInformation);
		}
	}
}